package com.fis.vaadin.utils;

import java.util.HashMap;

import com.fis.vaadin.VaadinForm;
import com.fis.vaadin.VaadinFormData;
import com.vaadin.ui.Field;
import com.vaadin.ui.Form;

/**
 * @author VinhNDQ
 *
 * @Company FPT-FIS-TES
 *
 * @date Dec 13, 2012
 */
public class BaseFormDetail extends Form {

//	private VaadinForm formLayout;
	private VaadinFormData formData;
	private boolean hasLayout = false;
	private HashMap<String, Field> mapFieldData;

	public BaseFormDetail(VaadinForm formLayout) throws Exception {

//		this.formLayout = formLayout;
		if (formLayout == null) {
			throw new Exception("Don't have form layout");
		}
		try {
			formData = formLayout.getFormData();
			hasLayout = (formData.getMapLayoutList().size() > 0);
			if (hasLayout)
				this.setLayout(formLayout);
			mapFieldData = formData.getMapFieldData();
		} catch (Exception ex) {
			ex.printStackTrace();
			formData = null;
			hasLayout = false;
			mapFieldData = null;
		}
	}

	@Override
	public void addField(Object propertyId, Field field) {
		if (!hasLayout || mapFieldData == null) {
			super.addField(propertyId, field);
		}
	}
}
